package com.marketing.auth;

import org.mybatis.spring.annotation.MapperScan;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.env.Environment;

/**
 * 智能营销系统认证服务启动类
 * 
 * @author Marketing Team
 * @version 1.0.0
 * @since 2025-09-24
 */
@SpringBootApplication
@EnableDiscoveryClient
@MapperScan("com.marketing.auth.mapper")
public class AuthServiceApplication {
    
    private static final Logger logger = LoggerFactory.getLogger(AuthServiceApplication.class);
    
    public static void main(String[] args) {
        logger.info("开始启动智能营销系统认证服务...");
        
        try {
            ConfigurableApplicationContext context = SpringApplication.run(AuthServiceApplication.class, args);
            Environment env = context.getEnvironment();
            
            String serverPort = env.getProperty("server.port", "8082");
            String contextPath = env.getProperty("server.servlet.context-path", "");
            String profile = env.getProperty("spring.profiles.active", "default");
            
            logger.info("认证服务启动成功!");
            logger.info("服务端口: {}", serverPort);
            logger.info("上下文路径: {}", contextPath.isEmpty() ? "/" : contextPath);
            logger.info("活跃配置文件: {}", profile);
            logger.info("本地访问地址: http://localhost:{}{}", serverPort, contextPath);
            logger.info("健康检查地址: http://localhost:{}{}/health", serverPort, contextPath);
            logger.info("Actuator监控地址: http://localhost:{}{}/actuator", serverPort, contextPath);
            
            System.out.println("\n" +
                    "====================================\n" +
                    "  智能营销系统认证服务启动成功！  \n" +
                    "====================================\n");
                    
        } catch (Exception e) {
            logger.error("认证服务启动失败: {}", e.getMessage(), e);
            System.exit(1);
        }
    }
}